package bank;

import java.util.ArrayList;

import exceptions.accountNotFound;

public class Account
{
    final String accountNumber;
    
    private String username;
    
    private String password;
    
    private double cash = 0;
    
    private double intrestrate = 2;
    
    private double loan = 0;
    
    private double loanrate = 5;
    
    private ArrayList<String> log = new ArrayList<String>();
    
    public Account(String username, String account, String password)
    {
        this.setUsername(username);
        this.accountNumber = account;
        this.setPassword(password);
    }
    
    public void monthlyEvents()
    {
        this.getInterest();
        this.loanIntrest();
    }
    
    

    public void getInterest()
    {
        cash = cash + ((cash * this.intrestrate)/100);
    }
    
    public void takeloan(double ammount)
    {
        loan = loan + ammount;
        cash= cash+ammount;
    }
    
    public void loanIntrest()
    {
        loan = loan + ((loan * this.loanrate)/100);
    }
    
    public void makePayment(String accountNumber, double amount) throws accountNotFound
    {
    	//TODO will this ammend this account also from the hash table or will this cause a seperate instance to be created?
    	Account found = BankVault.getAccount(accountNumber);
    	if(found != null)
    	{
    	 cash = cash - amount;
    	 found.receivePayment(accountNumber, amount);
    	}
    	else
    	{
    		throw new accountNotFound();    		
    	}
    	
    }
 
    public void receivePayment(String accountNumber, double amount)
    {
        //TODO inserted code below check
        log.add("Payment received from " + accountNumber + " for the total of $" + new Double(amount).toString());
        cash = cash + amount;
    }


    public String getAccountNumber()
    {
        return accountNumber;
    }


    public double getCash()
    {
        return cash;
    }


    public void setCash(double cash)
    {
        this.cash = cash;
    }


    public ArrayList<String> getLog()
    {
        return log;
    }


    public void setLog(ArrayList<String> log)
    {
        this.log = log;
    }


    public String getPassword()
    {
        return password;
    }


    public void setPassword(String password)
    {
        this.password = password;
    }


    public String getUsername()
    {
        return username;
    }


    public void setUsername(String username)
    {
        this.username = username;
    }
    
    public double getIntrestrate()
    {
        return intrestrate;
    }

    public void setIntrestrate(double intrestrate)
    {
        this.intrestrate = intrestrate;
    }

    public double getLoan()
    {
        return loan;
    }

    public void setLoan(double loan)
    {
        this.loan = loan;
    }

    public double getLoanrate()
    {
        return loanrate;
    }

    public void setLoanrate(double loanrate)
    {
        this.loanrate = loanrate;
    }
    
    
    
}
